/*
 * The MIT License
 *
 * Copyright (c) 2010, Bharathwaaj Srinivasan, bluegenetic@gmail.com, bharathwaaj.s@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "curltweet_api.h"

int main()
{
    CtError e_retval = ERR_NONE;
    int32_t s32_count = 0;
    CurlTweet p_s_ctHandle = NULL;
    StatusRoot s_statuses;
    CtString s_username, s_password;
    Status *p_s_status = NULL;
    StatusParams s_params;
    char array[20] = {"celestialsys"};
    char password[40] = {"welcome1"};

    s_username.p_u8_string = array;
    s_password.p_u8_string = password;
    s_username.u32_stringLen = strlen(s_username.p_u8_string);
    s_password.u32_stringLen = strlen(s_password.p_u8_string);

    e_retval = curltweet_init ();
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    e_retval = curltweet_alloc (&p_s_ctHandle);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    e_retval = curltweet_logIn (p_s_ctHandle, &s_username, &s_password);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }


    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_PUBLIC, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

#if 0
    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_PUBLIC, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
#endif
#if 1
    printf("Getting Home Timeline\n");
    s32_count = 0;
    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_HOME, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
#endif
#if 1
    printf("Getting Friends timeline\n");
    s32_count = 0;
    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_FRIENDS, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
#endif
#if 1
    printf("Getting User timeline\n");
    s32_count = 0;
    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_USER, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
#endif
#if 1
    printf("Getting Mentions timeline\n");
    s32_count = 0;
    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_MENTIONS, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
#endif
#if 1
    printf("Getting Retweeted by me timeline\n");
    s32_count = 0;
    e_retval = curltweet_getTimeline (p_s_ctHandle, TIMELINE_RETWEETED_BY_ME, NULL, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    printf("Freeing statuses\n");
    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
#endif
    printf("Enter the status id\n");
    scanf("%lld", &(s_params.u64_statusId));
    s32_count = 0;
    curltweet_status (p_s_ctHandle, STATUS_SHOW, &s_params, &s_statuses);
    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    printf("Freeing statuses\n");
    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    memset(&s_params, 0, sizeof(s_params));
    printf("Enter the status to update\n");
    scanf("%s", s_params.a_u8_tweet);
    s32_count = 0;
    curltweet_status (p_s_ctHandle, STATUS_UPDATE, &s_params, &s_statuses);
    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    printf("Freeing statuses\n");
    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    memset(&s_params, 0, sizeof(s_params));
    printf("Enter the status id to destroy\n");
    scanf("%lld", &(s_params.u64_statusId));
    s32_count = 0;
    curltweet_status (p_s_ctHandle, STATUS_DESTROY, &s_params, &s_statuses);
    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    printf("Freeing statuses\n");
    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }

    memset(&s_params, 0, sizeof(s_params));
    printf("Enter the status id to retweet\n");
    scanf("%lld", &(s_params.u64_statusId));
    s32_count = 0;
    curltweet_status (p_s_ctHandle, STATUS_RETWEET, &s_params, &s_statuses);
    printf("Number of Statuses %d\n", s_statuses.u32_numOfStatuses);
    while (s32_count != s_statuses.u32_numOfStatuses) {
        p_s_status = (s_statuses.p_s_statusesArr + s32_count);

        printf("\n=========================================\n");
        printf("%s\n",   p_s_status->p_u8_postTime        );
        printf("%s\n",   p_s_status->p_u8_replyToUsername );
        printf("%s\n",   p_s_status->p_u8_tweet           );
        printf("%d\n",   p_s_status->eb_truncated         );
        printf("%d\n",   p_s_status->eb_favorited         );
        printf("%lld\n", p_s_status->u64_replyToStatusId);
        printf("%lld\n", p_s_status->u64_replyToUserId  );
        printf("%lld\n", p_s_status->u64_statusId       );
        printf("%s\n", p_s_status->s_userInfo.p_u8_username);
        printf("%s\n", p_s_status->s_userInfo.p_u8_fullname);
        printf("%s\n", p_s_status->s_userInfo.p_u8_location);
        printf("%d\n",   p_s_status->s_userInfo.u32_numFollowers     );
        printf("\n=========================================\n");

        s32_count++;
    }

    printf("Freeing statuses\n");
    e_retval = curltweet_freeStatuses ( p_s_ctHandle, &s_statuses);
    if (e_retval != ERR_NONE) {
        printf("Curl tweet error %d\n", e_retval);
    }
curltweet_logOut(p_s_ctHandle);
curltweet_free (p_s_ctHandle);
curltweet_cleanup ();
return 1;
}
